package com.yuxl.common.file.controller;

import com.yuxl.common.core.domain.R;
import com.yuxl.common.file.domain.GetUploadUrlReq;
import com.yuxl.common.file.utils.MinioFileUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.Map;


/**
 * @Author : yuxl
 * @create 2025/8/15 下午7:36
 */
@Tag(name = "Minio:文件")
@RequestMapping("/minio/file")
@RestController
public class MinioFileController {

     @Resource
     private MinioFileUtil minioFileUtil;

    @Operation(summary = "上传文件")
    @PostMapping(value = "/putObject", consumes = "multipart/form-data")
    public Mono<R<String>> putObject(@RequestPart("file") FilePart filePart, @RequestPart("path") String path, @RequestPart("contentType") String contentType){
        String filename = filePart.filename();
        return minioFileUtil.putObject(filePart,path,filename,contentType).map(R::ok);
    }

    @Operation(summary = "获取上传签名")
    @PostMapping("/getUploadUrl")
    public Mono<R<String>> getUploadUrl(@RequestBody GetUploadUrlReq req) {
        return minioFileUtil.getUploadUrl(req.getFileName()).map(R::ok);
    }
}
